<template>
	<div>
		<div class="searchForm">
		    <div style="display: flex;">
		        <div>
					用户手机号/姓名：
				</div>
				<div>
					<selectUser ref="selectUser" @getUserId="getUserId"  />
				</div>
				<div style="margin-left: 10px;">
				    <el-button type="primary" size="mini" @click="search">检索</el-button>
				    <el-button size="mini" @click="clearSearch">重置/检索</el-button>
				</div>
		    </div>
		</div>
		<br>
		<el-table  :data="list"
			 border  
			 style="width: 100%"
			>
			<el-table-column   align="center"  label="用户手机号">
				<template slot-scope="scope">
					<span v-if="scope.row.user_info">
						 {{scope.row.user_info.phone}}
					</span>
				</template>
			</el-table-column>
			<el-table-column   align="center"  label="用户姓名">
				<template slot-scope="scope">
					<span v-if="scope.row.user_info">
						{{scope.row.user_info.name}}
					</span>
				</template>
			</el-table-column>
			<el-table-column   align="center"  label="商品名称">
				<template slot-scope="scope">
					<span v-if="scope.row.goods_info">
						{{scope.row.goods_info.goods_name}}
					</span>
				</template>
			</el-table-column>
			<!-- <el-table-column   align="center"  label="价格">
				<template slot-scope="scope">
				    {{scope.row.goods_info.price}}
				</template>
			</el-table-column> -->
			<el-table-column   align="center"  label="串号">
				<template slot-scope="scope">
				    {{scope.row.code}}
				</template>
			</el-table-column>
			<el-table-column   align="center"  label="已读/未读">
				<template slot-scope="scope">
				    <el-switch
						 @change="changeReady(scope.row)"
						  v-model="scope.row.is_ready"
						 :inactive-value="'0'"
						 :active-value="'1'"
						 >
				    </el-switch>
				</template>
			</el-table-column>
			<el-table-column   align="center"    label="类型">
				<template slot-scope="scope">
					 <el-tag
						size="mini"
					    v-if="scope.row.type==1"
					    effect="dark">
					    申请出货
					  </el-tag>
					  <el-tag
						size="mini"
					     type="danger"
					     v-if="scope.row.type==2"
					     effect="dark">
					     申请退货
					   </el-tag>
				</template>
			</el-table-column>
			<el-table-column   align="center"    prop="returnCode"    label="退货码"></el-table-column>
			<el-table-column   align="center"    label="寄存/库存">
				<template slot-scope="scope">
					<el-tag
						size="mini"
					   v-if="scope.row.is_jc==1"
					   effect="dark">
					   寄存
					 </el-tag>
					 <el-tag
						size="mini"
					    type="success"
					    v-if="scope.row.is_jc==0"
					    effect="dark">
					    库存
					  </el-tag>
				</template>
			</el-table-column>
			<el-table-column   align="center"    prop="add_time"    label="添加时间"></el-table-column>
			
		</el-table>
		<div class="page">
		    <el-pagination
		            background
		            @size-change="pageChange"
		            @current-change="handleCurrentChange"
		            :current-page="page"
		            :page-size="pageSize"
		            layout="total, sizes, prev, pager, next, jumper"
		            :total="page_totle">
		    </el-pagination>
		</div>
		<el-dialog
		        :title="addTitle"
				:close-on-click-modal="false"
		        :visible.sync="formShow"
		        width="1000px"
		>
		  <div>
			  <el-form ref="form" label-width="80px">
				  <el-form-item label="系列说明">
						<el-input type="textarea" size="small" v-model="form.class_remark"
						></el-input>
				  </el-form-item>
				  <el-form-item >
				      <el-button type="primary" @click="confirm" size="small">确定</el-button>
				  </el-form-item>
			  </el-form>
		  </div>
		</el-dialog>
		
	</div>
</template>

<script>
	import selectUser from '@/components/selectUser.vue';
	export default {
		data(){
			return {
				title:"",
				page:1,
				pageSize:20,
				search_form:{
					class_name:'',
					brand_name:""
				},
				form:{
					id:null,
					class_remark:''
				},
				addTitle:'新增',
				isShow:false,
				table_name:'hs_class',
				mid:''
			}
		},
		components:{
			selectUser
		},
		mounted() {
			this.lodeList()
		},
		methods:{
			changeReady(row){
				let params = {
					id:row.id,
					is_ready:row.is_ready,
					table_name:'hs_user_application'
				}
				this.$post('/user/setReady',params,res=>{
					this.$post('/user/getNotReadyNumber',{},res=>{
						  this.$store.dispatch('settings/changeSetting', {
							key: 'app_count',
							value: res.data.data.app_count
						  })
						  this.$store.dispatch('settings/changeSetting', {
							key: 'act_count',
							value: res.data.data.act_count
						  })
					})
				})
			},
			getUserId(val){
				this.page = 1
				this.mid = val
			},
			clearSearch(){
				this.mid = ''
				this.page = 1
				this.$refs['selectUser'].mid = ''
				this.$refs['selectUser'].keywords = ''
				this.lodeList()
			},
			confirm(){
				this.$post('/prodectSys/editClass',this.form,res=>{
					if(res.data.code==200){
						this.$message.success('操作成功')
						this.formShow = false
						this.lodeList()
					}
				})
			},
			lodeList(){
				let params = {
					page:this.page,
					pageSize:this.pageSize,
					mid:this.mid
				}
				this.$post('/user/lodeApplicantion',params,res=>{
					let data = res.data.data
					this.page_totle = data.count
					this.list = data.result
				})
			},
		}
	}
</script>

<style>
</style>